package Clases;

import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.DriverManager;

public class ConexionMySql {
    private Connection conexion;
    final String bd="control_stock";
    final String user="root";
    final String password="12345";
    final String server="jdbc:mysql://localhost/"+bd;

    public ConexionMySql() {
        
    }
    
    @SuppressWarnings("UseSpecificCatch")
  public Connection conectar(){
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conexion = DriverManager.getConnection(server,user,password);
        }
        catch(Exception e){
            System.out.println("Imposible realizar conexion con la Base de Datos");
            System.out.println(e.toString());
        }
        return conexion;
    }

    
    
    public Connection getConexion(){
        return conexion;
    }

    public void cerrar(ResultSet rs){
        if(rs !=null){
            try{
                rs.close();
            }
            catch(Exception e){
                System.out.print("No es posible cerrar la Conexion");
            }
        }
    }

    public void cerrar(java.sql.Statement stmt){
        if(stmt !=null){
            try{
                stmt.close();
            }
                catch(Exception e){}
        }
    }

    public void destruir(){

        if(conexion !=null){
            try{
                conexion.close();
            }
                catch(Exception e){}
            }
        }
    
 
}
